<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="要素" prop="element">
        <el-input
          v-model="queryParams.element"
          placeholder="请输入要素"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="体征" prop="sign">
        <el-input
          v-model="queryParams.sign"
          placeholder="请输入体征"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="风险等级" prop="riskLevel">
        <el-input
          v-model="queryParams.riskLevel"
          placeholder="请输入风险等级"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="处置方式" prop="disposalMethod">
        <el-input
          v-model="queryParams.disposalMethod"
          placeholder="请输入处置方式"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="责任部门" prop="responsibleDepartment">
        <el-input
          v-model="queryParams.responsibleDepartment"
          placeholder="请输入责任部门"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段1" prop="overdueAlertSpare1">
        <el-input
          v-model="queryParams.overdueAlertSpare1"
          placeholder="请输入备用字段1"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段2" prop="overdueAlertSpare2">
        <el-input
          v-model="queryParams.overdueAlertSpare2"
          placeholder="请输入备用字段2"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段3" prop="overdueAlertSpare3">
        <el-input
          v-model="queryParams.overdueAlertSpare3"
          placeholder="请输入备用字段3"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段4" prop="overdueAlertSpare4">
        <el-input
          v-model="queryParams.overdueAlertSpare4"
          placeholder="请输入备用字段4"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="备用字段5" prop="overdueAlertSpare5">
        <el-input
          v-model="queryParams.overdueAlertSpare5"
          placeholder="请输入备用字段5"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="创建者ID" prop="createId">
        <el-input
          v-model="queryParams.createId"
          placeholder="请输入创建者ID"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="创建者姓名" prop="createName">
        <el-input
          v-model="queryParams.createName"
          placeholder="请输入创建者姓名"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="更新者ID" prop="updateId">
        <el-input
          v-model="queryParams.updateId"
          placeholder="请输入更新者ID"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="更新者姓名" prop="updateName">
        <el-input
          v-model="queryParams.updateName"
          placeholder="请输入更新者姓名"
          clearable
          
        />
      </el-form-item>
      <el-form-item label="账户ID" prop="accountId">
        <el-input
          v-model="queryParams.accountId"
          placeholder="请输入账户ID"
          clearable
          
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['yanjing:alert:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['yanjing:alert:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['yanjing:alert:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['yanjing:alert:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="alertList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="要素" align="center" prop="element" />
      <el-table-column label="体征" align="center" prop="sign" />
      <el-table-column label="风险等级" align="center" prop="riskLevel" />
      <el-table-column label="处置方式" align="center" prop="disposalMethod" />
      <el-table-column label="异常原因" align="center" prop="exceptionReason" />
      <el-table-column label="责任部门" align="center" prop="responsibleDepartment" />
      <el-table-column label="备用字段1" align="center" prop="overdueAlertSpare1" />
      <el-table-column label="备用字段2" align="center" prop="overdueAlertSpare2" />
      <el-table-column label="备用字段3" align="center" prop="overdueAlertSpare3" />
      <el-table-column label="备用字段4" align="center" prop="overdueAlertSpare4" />
      <el-table-column label="备用字段5" align="center" prop="overdueAlertSpare5" />
      <el-table-column label="创建者ID" align="center" prop="createId" />
      <el-table-column label="创建者姓名" align="center" prop="createName" />
      <el-table-column label="更新者ID" align="center" prop="updateId" />
      <el-table-column label="更新者姓名" align="center" prop="updateName" />
      <el-table-column label="账户ID" align="center" prop="accountId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['yanjing:alert:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['yanjing:alert:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      v-model:page.sync="queryParams.pageNum"
      v-model:limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改逾期未处置预警对话框 -->
    <el-dialog :title="title" v-model:visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="要素" prop="element">
          <el-input v-model="form.element" placeholder="请输入要素" />
        </el-form-item>
        <el-form-item label="体征" prop="sign">
          <el-input v-model="form.sign" placeholder="请输入体征" />
        </el-form-item>
        <el-form-item label="风险等级" prop="riskLevel">
          <el-input v-model="form.riskLevel" placeholder="请输入风险等级" />
        </el-form-item>
        <el-form-item label="处置方式" prop="disposalMethod">
          <el-input v-model="form.disposalMethod" placeholder="请输入处置方式" />
        </el-form-item>
        <el-form-item label="异常原因" prop="exceptionReason">
          <el-input v-model="form.exceptionReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="责任部门" prop="responsibleDepartment">
          <el-input v-model="form.responsibleDepartment" placeholder="请输入责任部门" />
        </el-form-item>
        <el-form-item label="备用字段1" prop="overdueAlertSpare1">
          <el-input v-model="form.overdueAlertSpare1" placeholder="请输入备用字段1" />
        </el-form-item>
        <el-form-item label="备用字段2" prop="overdueAlertSpare2">
          <el-input v-model="form.overdueAlertSpare2" placeholder="请输入备用字段2" />
        </el-form-item>
        <el-form-item label="备用字段3" prop="overdueAlertSpare3">
          <el-input v-model="form.overdueAlertSpare3" placeholder="请输入备用字段3" />
        </el-form-item>
        <el-form-item label="备用字段4" prop="overdueAlertSpare4">
          <el-input v-model="form.overdueAlertSpare4" placeholder="请输入备用字段4" />
        </el-form-item>
        <el-form-item label="备用字段5" prop="overdueAlertSpare5">
          <el-input v-model="form.overdueAlertSpare5" placeholder="请输入备用字段5" />
        </el-form-item>
        <el-form-item label="创建者ID" prop="createId">
          <el-input v-model="form.createId" placeholder="请输入创建者ID" />
        </el-form-item>
        <el-form-item label="创建者姓名" prop="createName">
          <el-input v-model="form.createName" placeholder="请输入创建者姓名" />
        </el-form-item>
        <el-form-item label="更新者ID" prop="updateId">
          <el-input v-model="form.updateId" placeholder="请输入更新者ID" />
        </el-form-item>
        <el-form-item label="更新者姓名" prop="updateName">
          <el-input v-model="form.updateName" placeholder="请输入更新者姓名" />
        </el-form-item>
        <el-form-item label="账户ID" prop="accountId">
          <el-input v-model="form.accountId" placeholder="请输入账户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOverduealert, getOverduealert, delOverduealert, addOverduealert, updateOverduealert } from "@/api/business/overduealert";

export default {
  name: "Overduealert",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 逾期未处置预警表格数据
      alertList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        element: null,
        sign: null,
        riskLevel: null,
        disposalMethod: null,
        exceptionReason: null,
        responsibleDepartment: null,
        overdueAlertSpare1: null,
        overdueAlertSpare2: null,
        overdueAlertSpare3: null,
        overdueAlertSpare4: null,
        overdueAlertSpare5: null,
        createId: null,
        createName: null,
        updateId: null,
        updateName: null,
        accountId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询逾期未处置预警列表 */
    getList() {
      this.loading = true;
      listOverduealert(this.queryParams).then(response => {
        this.alertList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        element: null,
        sign: null,
        riskLevel: null,
        disposalMethod: null,
        exceptionReason: null,
        responsibleDepartment: null,
        overdueAlertSpare1: null,
        overdueAlertSpare2: null,
        overdueAlertSpare3: null,
        overdueAlertSpare4: null,
        overdueAlertSpare5: null,
        createId: null,
        createName: null,
        createTime: null,
        updateId: null,
        updateName: null,
        updateTime: null,
        accountId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加逾期未处置预警";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOverduealert(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改逾期未处置预警";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOverduealert(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOverduealert(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除逾期未处置预警编号为"' + ids + '"的数据项？').then(function() {
        return delOverduealert(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('yanjing/alert/export', {
        ...this.queryParams
      }, `alert_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
